package com.example.task1.ui.AllService.volunteer;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.base.BaseActivity;
import com.example.task1.bean.VolunteerBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import java.util.HashMap;

import retrofit2.Call;

public class VolunteerDetailActivity extends BaseActivity {

    private TextView tvTitle;
    private TextView tvUndertaker;
    private TextView tvRequireText;
    private TextView tvDetail;
    private TextView tvStartAt;
    private Button btnSave;
    private VolunteerBean.RowsDTO date;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volunteer_detail);
        initView();
        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HashMap<String, Object> map = new HashMap<>();
                map.put("activityId", date.getId());
                map.put("newState", true);
                Call<ApiResp> post = Api.api().post(MyApplication.TOKEN, "/prod-api/api/volunteer-service/register", Api.getBody(map));
                Api.send(post, ApiResp.class, new CallBack<ApiResp>() {
                    @Override
                    public void success(ApiResp data) {
                        MyApplication.show("报名成功");
                        finish();
                    }

                    @Override
                    public void error(String msg) {

                    }
                });
            }
        });
    }

    @Override
    public String getMyTitle() {
        return "活动详情";
    }

    private void initView() {
        tvTitle = findViewById(R.id.tv_title);
        tvUndertaker = findViewById(R.id.tv_undertaker);
        tvRequireText = findViewById(R.id.tv_requireText);
        tvDetail = findViewById(R.id.tv_detail);
        tvStartAt = findViewById(R.id.tv_startAt);
        btnSave = findViewById(R.id.btn_save);
        date = MyApplication.Volunteer.date;
        tvDetail.setText("活动详情：" + date.getDetail());
        tvRequireText.setText("报名要求：" + date.getRequireText());
        tvStartAt.setText("----" + date.getStartAt());
        tvTitle.setText(date.getTitle());
        tvUndertaker.setText("承办单位：" + date.getUndertaker());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyApplication.Volunteer.date = null;
    }
}